generate_profile

This function generates the log file containing the results of the profiling (see remarks).

bool generate_profile(string filename)

Parameters:
filename
The name of the file to write to.

Return value:
true on success, false on failure.

Remarks:
The BGT profiler follows the code's execution chain and times each function that is called throughout the game. The profiler will then write a log of all the accumulated statistics, which include the overall length of time each function took to execute throughout the game's lifetime, and a percentage based on this. This is useful for checking to see if any functions need further optimisation in order to improve overall performance and speed. For more information about optimising your code, please consult the tutorial that deals with optimization strategies.

For the profiler to work accurately, you should call start_profiling at the start of your script (usually in main) before any other function is called, and call generate_profile immediately before your game is due to exit.

This function will generate the log file, stop the profiler, and reset it.

Please note that when you profile debug builds or source code, the results are considerably more accurate as compared with release builds. In debug builds and when running source code, some execution speed is sacrificed for the benefit of being able to diagnose performance bottlenecks and other problems more easily. This is not the case with release builds which means that the results that the profiler produces, while not entirely inaccurate, should not be relied upon.

Example:
/*
Write a series of functions that will take different speeds and have the profiler give us some information.
lets_go and lets_finish_here will of course show varying results depending on how long it takes the user to close the message box.
On a system using a 1.8 GHZ duel core processor, the results show as follows:

void lets_do_some_more(): 8055 ms (76.9%)
void lets_finish_here(): 1122 ms (10.71%)
void another_loop(): 879 ms (8.39%)
void lets_go(): 418 ms (3.99%)

*/

void main()
{
start_profiling();
lets_go();
lets_do_some_more();
lets_finish_here();
}

void lets_go()
{
alert("Hi!", "This program demonstrates the use of the BGT profiler.");
}

void lets_do_some_more()
{
string test;
for(int counter=0; counter<13579000; counter++)
{
test+="a";
if(counter%1000==0)
{
test="";
}
}
another_loop();
}

void another_loop()
{
for(int counter=0; counter<13500000; counter++)
{
int check=1000;
}
}

void lets_finish_here()
{
alert("Finished.", "The profiler will now generate the log.");
generate_profile("profiler.log");
}